import './index.scss'
import Header from '../../components/Header'
import Aside from '../../components/Aside'
import { updateFeedback, getFeedbackDetail } from '../../api/feedback'

export default {
  name: 'Detail',
  components: {
    Header,
    Aside,
  },
  data() {
    return {
      reply: '',
      feedbackId: '',
      feedbackDetail: '',
      showHeader: '',
      showSidebar: '',
    }
  },
  mounted() {
    if (this.$store.state.settings.showHeader == 'true') {
      this.showHeader = true
    } else {
      this.showHeader = false
    }
    if (this.$store.state.settings.showSidebar == 'true') {
      this.showSidebar = true
    } else {
      this.showSidebar = false
    }
    this.feedbackId = this.$route.query.id
    this.getFeedbackDetail()
  },
  methods: {
    submit() {
      let data = {
        reply: this.reply,
      }
      updateFeedback(this.feedbackId, data, this)
        .then((res) => {
          this.$message.success(res.data.message)
          if (res.data.code === '1') {
            this.$router.go(-1)
          }
        })
        .catch((error) => {
          this.$message.warning(error.response.data.message)
        })
    },
    getFeedbackDetail() {
      let params = {}
      getFeedbackDetail(this.feedbackId, params, this)
        .then((res) => {
          if (res.data.code === 1) {
            this.feedbackDetail = res.data.content
          }
        })
        .catch((error) => {
          this.$message.warning(error.response.data.message)
        })
    },
    incisionImgs(imgs) {
      if (imgs) {
        return imgs.split(',')
      } else {
        return []
      }
    },
  },
  head() {
    return {
      title: '反馈详情 - EasyAPI意见反馈',
      meta: [
        { hid: 'description', name: 'description', content: '反馈详情' },
        { hid: 'keyword', name: 'keyword', content: '反馈详情' },
      ],
    }
  },
}
